package cn.kais.drawer.bean;

import cn.kais.drawer.menu.MenuBean;
import cn.kais.drawer.unit.UnitVideo;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.awt.*;
import java.awt.image.BufferedImage;

public class BeanVideo extends BeanBasic {

    public String src = "https://bowtz-lcd.oss-cn-hangzhou.aliyuncs.com/res/lcd/material/video/0/1/20240718/ce02483a9e4644af9bbe8569cdfb6993.mp4"; // 图片地址

    public int top;
    public int left;
    public int width;
    public int height;

    public Graphics2D sd; // 绘制

    public BeanVideo(Graphics2D sd, JSONObject com) {
        menu = MenuBean.VIDEO;
        System.out.println();
        this.sd = sd;
        this.top = com.getInteger("top");
        this.left = com.getInteger("left");
        this.width = com.getInteger("width");
        this.height = com.getInteger("height");

        JSONArray list = com.getJSONArray("videoList");
        if (list != null && !list.isEmpty()) {
            JSONObject item = list.getJSONObject(0);
            this.src = item.getString("url");
        }
        System.out.println(this.src);
        this.create();
    }

    private void create() {
        BufferedImage ima = UnitVideo.iCoverBuffer(this.src);
        if (ima != null) {
            sd.drawImage(ima, this.left, this.top, this.width, this.height, null);
        }
    }

}
